Create conf/machine/raspi4-custom.md
# keep the original machine as an override with high prio
MACHINEOVERRIDES =. "raspberrypi4:"
require conf/machine/raspberrypi4.conf
MACHINE_PREFIX_raspi4-custom = "raspberrypi4"
# start of our costumizations:
RPI_USE_U_BOOT = "1"
ENABLE_UART = "1"
Modify the linux kernel with configuration fragments in Yocto
This also works for U-boot.
Extract the rootfs and have a look at its disk usage using ncdu.
Install this service into your image using a recipe.
[Unit]
Description=Generate random hostname on first boot
ConditionFirstBoot=yes
Before=first-boot-complete.target
Wants=first-boot-complete.target
[Service]
Type=oneshot
ExecStart=/bin/bash -c 'hostnamectl set-hostname "system-$(cat /etc/machine-id | sha256sum | cut -c1-8)"'
RemainAfterExit=yes
[Install]
WantedBy=multi-user.target
The ConditionFirstBoot is fulfilled if /etc/machine-id is missing. Be default Yocto adds an empty machine-id file to your image.
Adding
remove_machine_id() {
rm -f ${IMAGE_ROOTFS}/etc/machine-id
}
ROOTFS_POSTPROCESS_COMMAND:append = "remove_machine_id "
to your image recipe will not work, because the file is added in the IMAGE_PREPROCESS_COMMAND which is run after the ROOTFS_POSTPROCESS_COMMAND. See the graphic in the docs.
Add this instead:
IMAGE_PREPROCESS_COMMAND:remove = "systemd_preset_all"